﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Dycox.Validation
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class RegexValidatorAttribute : ValidatorAttribute
    {
        public RegexValidatorAttribute(string pattern)
            : base(pattern)
        {

        }

        private RegexOptions _options;

        public RegexOptions Options
        {
            get { return _options; }
            set { _options = value; }
        }


        protected override Validator CreateValidator(object[] parameters, System.ComponentModel.ITypeDescriptorContext context)
        {
            RegexValidator val = new RegexValidator();
            val.Pattern = (string)parameters[0];
            val.Options = _options;
            return val;
        }
    }
}
